package com.yanqu.road.server.cmd.assistant.assistantSkin;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.assistant.AssistantSkinProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.assistant.AssistantSkinMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_SEE_OTHER_ASSISTANT, desc = "查看其他玩家小助手")
public class SeeOtherAssistantCmd extends AbstractCommand {
    private long userId;
    private long serverId;
    private int topNum;
    private AssistantSkinProto.SeeOtherAssistantReqMsg msg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        msg = AssistantSkinProto.SeeOtherAssistantReqMsg.parseFrom(packet.getBytes());
        serverId = msg.getServerId();
        userId = msg.getPlayerId();
        topNum = msg.getTopDecorationsNum();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (serverId == GameServer.getInstance().getServerId()) {
            //本服查看他人小助理
            AssistantSkinProto.SeeOtherAssistantRespMsg.Builder respMsg;
            respMsg = AssistantSkinMgr.getSeeAssistantMsg(userId, topNum);
            player.sendPacket(ClientProtocol.U_SEE_OTHER_ASSISTANT, respMsg);
        } else {
            //跨服
            player.sendPacket(CrossProtocol.C_CROSS_SEE_OTHER_ASSISTANT, msg.toBuilder());
        }

    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
